package com.djsearch.adapter;

import java.util.List;

import com.djsearch.R;
import com.djsearch.bean.SortBean;
import com.djsearch.data.ImageManager;
import com.djsearch.data.RequestImage;
import com.djsearch.ui.LocInfoActivity;
import com.djsearch.ui.SearchResultActivity;
import com.djsearch.ui.WebViewActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.style.BulletSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class WanNengChildListAdapter extends BaseAdapter{

	private Context mContext;
	private List<SortBean> sortList;
	private Bitmap mbitmap;
	public WanNengChildListAdapter(Context context,List<SortBean> list){
		mContext = context;
		sortList = list;
		Bitmap bitmap = ImageManager.drawableToBitmap(mContext.getResources().getDrawable(R.drawable.taogou),150.0f);
		mbitmap = (ImageManager.resizeImage(bitmap, 100.0f));
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return sortList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return sortList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	public void refresh(List<SortBean> sortList) {
		this.sortList = sortList;
		notifyDataSetChanged();
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		convertView = LayoutInflater.from(mContext).inflate(
				R.layout.wanneng_search_childlist_item, null);// 用LayoutInflater装载布局。
		TextView parentText = (TextView)convertView.findViewById(R.id.childText);
		parentText.setText(sortList.get(position).getSubjectName());
		ImageView childImg = (ImageView)convertView.findViewById(R.id.childListImg);
		String url = sortList.get(position).getUrl();
		final String newUrl = url.substring(7,url.lastIndexOf("?"));
//		String newUrlTwo = newUrlOne.substring(0,21);
//		String newUrlThree = newUrlOne.substring(25);
//		final String newUrl = newUrlTwo + newUrlThree;
//		RequestImage.getIntance(mbitmap, "Search").download(sortList.get(position).getSubjectImage(), childImg);
//		http://119.161.221.204:8088/awp/awp/jsp/business!p.shtml?data={"queryByType":"美食","page":"1","pageNum":"10"}
//		119.161.221.204:8088/awp/awp/jsp/business!p.shtml?data={"queryByType":"美食","page":"1","pageNum":"10"}
//		119.161.221.204:8088 119.161.221.204:8088/awp/jsp/business!p.shtml
		convertView.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(mContext,LocInfoActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
				Bundle bundle = new Bundle();
				bundle.putString("type", "1");
				bundle.putString("search", sortList.get(position).getSubjectName());
			    intent.putExtras(bundle);
		        mContext.startActivity(intent);
		        ((Activity) mContext).overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
			}
		});
		return convertView;
	}

}
